package grid.barracks
{
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import flash.text.TextFormat;

	public class rax  extends Sprite
	{
		// DESTROYER - 5 BLOCKS
		// WRAITH    - 3 BLOCKS SAME ROW
		// HAMMER    - 4 BLOCKS, SQUARE
		// KILLBIKE  - 2 BLOCKS
		// OCULUS    - 3 BLOCKS
		[Embed(source="assets/skullIcon.png")]
		public var skullSymbol:Class; 
		
		[Embed(source="assets/explosionIcon.png")]
		private var explosionSymbol:Class; 
		
		[Embed(source="assets/lockIcon.png")]
		public var lockSymbol:Class; 
		
		[Embed(source="assets/fire_skull.jpg")]
		public var fireSkull:Class;
		
		[Embed(source="assets/skull_lock.jpg")]
		public var skullLock:Class;
		
		
		public var unit:Sprite = new Sprite();
		public var selectedUnit;
		public var totalUnits = new Array();
		public function rax()
		{
		}
			//Start up
			public static function units()
			{
				
			}
			
			//Creates destroyer Unit
			public function create_Destroyer(thumbnail=false,index=false)
			{
				unit = new Sprite();
				var grid1 = new Sprite();
				var grid2 = new Sprite();
				var grid3 = new Sprite();
				var grid4 = new Sprite();
				var grid5 = new Sprite();
				
				grid1.graphics.beginFill(0x1ba4fa,1);
				grid1.graphics.drawRect(0,0,60,60);
				grid1.graphics.endFill();
				
				grid2.graphics.beginFill(0x1ba4fa,1);
				grid2.graphics.drawRect(70,0,60,60);
				grid2.graphics.endFill();
				
				grid3.graphics.beginFill(0x1ba4fa,1);
				grid3.graphics.drawRect(140,0,60,60);
				grid3.graphics.endFill();
				
				grid4.graphics.beginFill(0x1ba4fa,1);
				grid4.graphics.drawRect(70,-70,60,60);
				grid4.graphics.endFill();
				
				grid5.graphics.beginFill(0x1ba4fa,1);
				grid5.graphics.drawRect(70,70,60,60);
				grid5.graphics.endFill();
				
				unit.addChild(grid1);
				unit.addChild(grid2);
				unit.addChild(grid3);
				unit.addChild(grid4);
				unit.addChild(grid5);
				unit.name = "destroyer";
				if(thumbnail){unit.scaleX = 0.2;unit.scaleY=0.2;}
				if(index)unit.getChildAt(index).transform.colorTransform = new ColorTransform(0,0,0,1,Number(27),Number(164),Number(250));
				if(index==false)unit.addEventListener(MouseEvent.CLICK,selectUnit);
				if(index==false)totalUnits["destroyer"] = {ID:unit.name,Unit:unit};
				return unit;
			}
			
			//Creates wrath Unit
			public function create_Wraith(thumbnail=false):Sprite
			{
				unit = new Sprite();
				var grid1 = new Sprite();
				var grid2 = new Sprite();
				var grid3 = new Sprite();
				
				grid1.graphics.beginFill(0x1ba4fa,1);
				grid1.graphics.drawRect(0,0,60,60);
				grid1.graphics.endFill();
				
				grid2.graphics.beginFill(0x1ba4fa,1);
				grid2.graphics.drawRect(70,0,60,60);
				grid2.graphics.endFill();
				
				grid3.graphics.beginFill(0x1ba4fa,1);
				grid3.graphics.drawRect(140,0,60,60);
				grid3.graphics.endFill();
				
				unit.addChild(grid1);
				unit.addChild(grid2);
				unit.addChild(grid3);
				unit.name = "wraith";
				if(thumbnail){unit.scaleX = 0.2;unit.scaleY=0.2;}
				unit.addEventListener(MouseEvent.CLICK,selectUnit);
				totalUnits["wraith"] = {ID:unit.name,Unit:unit};
				return unit;
			}
			
			//Creates hammer Unit
			public function create_Hammer(thumbnail=false)
			{
				unit = new Sprite();
				var grid1 = new Sprite();
				var grid2 = new Sprite();
				var grid3 = new Sprite();
				var grid4 = new Sprite();
				
				grid1.graphics.beginFill(0x1ba4fa,1);
				grid1.graphics.drawRect(0,0,60,60);
				grid1.graphics.endFill();
				
				grid2.graphics.beginFill(0x1ba4fa,1);
				grid2.graphics.drawRect(70,0,60,60);
				grid2.graphics.endFill();
				
				grid3.graphics.beginFill(0x1ba4fa,1);
				grid3.graphics.drawRect(0,70,60,60);
				grid3.graphics.endFill();
				
				grid4.graphics.beginFill(0x1ba4fa,1);
				grid4.graphics.drawRect(70,70,60,60);
				grid4.graphics.endFill();
				
				unit.addChild(grid1);
				unit.addChild(grid2);
				unit.addChild(grid3);
				unit.addChild(grid4);
				unit.name = "hammer";
				if(thumbnail){unit.scaleX = 0.2;unit.scaleY=0.2;}
				unit.addEventListener(MouseEvent.CLICK,selectUnit);
				totalUnits["hammer"] = {ID:unit.name,Unit:unit};
				return unit;
			}
			
			//Creates killbike Unit
			public function create_killBike(thumbnail=false)
			{
				unit = new Sprite();
				var grid1 = new Sprite();
				var grid2 = new Sprite();
				var grid3 = new Sprite();
				
				grid1.graphics.beginFill(0x1ba4fa,1);
				grid1.graphics.drawRect(0,0,60,60);
				grid1.graphics.endFill();
				
				grid2.graphics.beginFill(0x1ba4fa,1);
				grid2.graphics.drawRect(70,70,60,60);
				grid2.graphics.endFill();
				
				unit.addChild(grid1);
				unit.addChild(grid2);
				unit.name = "killBike";
				if(thumbnail){unit.scaleX = 0.2;unit.scaleY=0.2;}
				unit.addEventListener(MouseEvent.CLICK,selectUnit);
				totalUnits["killBike"] = {ID:unit.name,Unit:unit};
				return unit;
			}
			
			//Creates oculus Unit
			public function create_Oculus(thumbnail=false)
			{
				unit = new Sprite();
				var grid1 = new Sprite();
				var grid2 = new Sprite();
				var grid3 = new Sprite();
				var grid4 = new Sprite();
				
				grid1.graphics.beginFill(0x1ba4fa,1);
				grid1.graphics.drawRect(0,0,60,60);
				grid1.graphics.endFill();
				
				grid2.graphics.beginFill(0x1ba4fa,1);
				grid2.graphics.drawRect(0,70,60,60);
				grid2.graphics.endFill();
				
				grid3.graphics.beginFill(0x1ba4fa,1);
				grid3.graphics.drawRect(70,0,60,60);
				grid3.graphics.endFill();
				
				grid4.graphics.beginFill(0x1ba4fa,1);
				grid4.graphics.drawRect(0,-70,60,60);
				grid4.graphics.endFill();
				
				unit.addChild(grid1);
				unit.addChild(grid2);
				unit.addChild(grid3);
				unit.addChild(grid4);
				unit.name = "oculus";
				if(thumbnail){unit.scaleX = 0.2;unit.scaleY=0.2;}
				unit.addEventListener(MouseEvent.CLICK,selectUnit);
				totalUnits["oculus"] = {ID:unit.name,Unit:unit};
				return unit;
			}
		
			
			// EVENTS
			public function selectUnit(evt:Event)
			{
				selectedUnit = evt.target.parent.name;
				for each(var o in totalUnits)
				{
						o.Unit.transform.colorTransform = new ColorTransform(0,0,0,1,Number(27),Number(164),Number(250));
				}	
				evt.target.parent.transform.colorTransform = new ColorTransform(0,0,0,1,Number(238),Number(25),Number(25));
			}
			
			public function selectUnitDestroyed(unit)
			{
				//selectedUnit = evt.target.parent.name;
				/*for each(var o in totalUnits)
				{
					o.Unit.transform.colorTransform = new ColorTransform(0,0,0,1,Number(27),Number(164),Number(250));
				}
				*/
				unit.transform.colorTransform = new ColorTransform(0,0,0,1,Number(238),Number(25),Number(25));
			}
			
			public function all2Default()
			{
				for each(var o in totalUnits)
				{
					o.Unit.transform.colorTransform = new ColorTransform(0,0,0,1,Number(27),Number(164),Number(250));
				}
			}
			
			public function getUnitColoring(unit)
			{
				switch(unit)
				{
					case "wraith":
						return 0x3bcdcb;
						break;	
					case "hammer":
						return 0x7c726c;
						break;
					case "killBike":
						return 0x3758e3;
						break;
					case "oculus":
						return 0xc1bfad;
						break;
					case "destroyer":
						return 0xf10a3b;
						break;
				}
			}
			
			
			public function createEX(black=false,double=0)
			{
				var EX = new Sprite();
				var line1:Sprite = new Sprite();
				var line2:Sprite = new Sprite();
				
				if(double!=0)
				{
					if(double==1)
					{
						var img = new this.fireSkull();
						img.width=60;
						img.height=60;
						line1.addChild(img);
						EX.addChild(line1);
					}
					else
					{
						var img = new this.skullLock();
						img.width=60;
						img.height=60;
						line1.addChild(img);
						EX.addChild(line1);
					}
				}
				else
				{
					var img = new this.explosionSymbol();
					var img2;
					if(black)img2 = new this.lockSymbol();
					black?line2.addChild(img2):line1.addChild(img);//line1.graphics.beginFill(0x898989):line1.graphics.beginFill(0x1ba4fa);
					line1.x = 12;
					line2.x = 10;
					//line1.graphics.drawRect(0,0,4,112);
					//line1.graphics.endFill();
					//line1.rotation = -45;
					
					//black?line2.graphics.beginFill(0x898989):line2.graphics.beginFill(0x1ba4fa);
					//line2.graphics.drawRect(0,0,4,112);
					//line2.graphics.endFill();
					//line2.x=60;
					black?EX.addChild(line2):EX.addChild(line1);//trace("no 2nd line");
				}
				return EX;
			}
	}
}